package com.example.eliliya.intent_receiver_injava;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.IntentFilter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity_intentreceiverinjava extends AppCompatActivity {
    private Button registerButton=null;
    private Button unregisterButton=null;
    private SMSReceiverActivity smsReceiver=null;
    private static final String SMS_ACTION="android.provider.Telephony.SMS_RECEIVED";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_intentreceiverinjava);
        registerButton=(Button)findViewById(R.id.register);
        registerButton.setOnClickListener(new RegisterReceiverListener());
        unregisterButton=(Button)findViewById(R.id.unregister);
        unregisterButton.setOnClickListener(new UnRegisterReceiverListener());
    }
    class RegisterReceiverListener implements OnClickListener{
        public void onClick(View v){
            smsReceiver=new SMSReceiverActivity();
            IntentFilter filter=new IntentFilter();
            filter.addAction(SMS_ACTION);
            MainActivity_intentreceiverinjava.this.registerReceiver(smsReceiver,filter);
        }
    }
    class UnRegisterReceiverListener implements OnClickListener{
        public void onClick(View v){
            MainActivity_intentreceiverinjava.this.unregisterReceiver(smsReceiver);
        }
    }
}
